
#include "Ouden\ouden.h"

#include "CTestEntity2.h"

using ouden::scene::ODN_Scene;
using ouden::scene::ODN_SceneObject;
using ouden::input::ODN_InputReceiver;
using ouden::utility::Vector3D;
using ouden::utility::RGBAColor;

class CTestEntity : public ODN_SceneObject, public ODN_InputReceiver
{

private:
	
	enum Commands { 
					Up=0,
					Down,
					Left,
					Right,
					Jump
				};

public:
	
	CTestEntity() : ODN_SceneObject(), color(RGBAColor(1, 1, 1, 1)), texture(0)
	{
		
		//Set control keys
		addInputCommand(Up, VK_UP);
		addInputCommand(Down, VK_DOWN);
		addInputCommand(Left, VK_LEFT, VK_HOME);
		addInputCommand(Right, VK_RIGHT);
		addInputCommand(Jump, VK_SPACE);
		
	}
	virtual ~CTestEntity()		{}
	
	//Main update function
	virtual bool Update()
	{
		
		pos[1] += 0.1;
		
		//if (ouden::input::getInputHandler()->isKeyDown(VK_SPACE)) CTestEntity2* c = new CTestEntity2(scene);
		
	}
	
	virtual bool Draw()
	{
		
		glColor4f(color.r, color.g, color.b, color.a);
		
		glBindTexture(GL_TEXTURE_2D, texture);
		
		glBegin(GL_TRIANGLES);
			
			glTexCoord2f(0, 0);
			glVertex3f(pos[0], pos[1], pos[2]);
			
			glTexCoord2f(1, 0);
			glVertex3f(pos[0] + 20, pos[1], pos[2]);
			
			glTexCoord2f(0, 1);
			glVertex3f(pos[0], pos[1] + 300, pos[2]);
			
		glEnd();
		
		glBindTexture(GL_TEXTURE_2D, 0);
		
	}
	
	virtual void onInputCommand(int Name)
	{
		
		switch (Name) {
			
			case Up : 
				
				pos[1] += 2;
				
				break;
				
			case Down : 
				
				pos[1] -= 2;
				
				break;
				
			case Left : 
				
				pos[0] -= 2;
				
				break;
				
			case Right : 
				
				pos[0] += 2;
				
				break;
				
			case Jump : 
				
				CTestEntity2* c = new CTestEntity2();		
				
				break;
				
		}
		
	}
	
	void setColor(RGBAColor c)		{ color = c; }
	void setTexture(GLuint t)		{ texture = t; }
	
private:
	
	//Object properties
	RGBAColor 	color;
	GLuint 		texture;
	
};
